package com.qk.management.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qk.domain.user.UserDO;
import com.qk.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;
import com.qk.dto.user.UserDTO;

@Mapper
public interface UserMapper extends BaseMapper<User> {

    List<UserDO> getUsers(UserDTO userDto);

    int insert(User user);

    void deleteByIds(List<Integer> ids);

    @Select("SELECT id, username, password, name, phone, email, gender, status, dept_id, role_id, image, remark, create_time, update_time FROM t_user WHERE id = #{id}")
    User selectById(Integer id);

    @Update("UPDATE t_user SET username=#{username}, password=#{password}, name=#{name}, phone=#{phone}, email=#{email}, gender=#{gender}, status=#{status}, dept_id=#{deptId}, role_id=#{roleId}, image=#{image}, remark=#{remark}, update_time=#{updateTime} WHERE id=#{id}")
    void update(User user);

    @Select("SELECT * FROM t_user WHERE username = #{username}")
    User selectUserByUsername(String username);

    @Select("SELECT * FROM t_user WHERE name = #{name}")
    User selectUserByName(String name);

    @Select("SELECT * FROM t_user")
    List<User> selectUserList();

    @Select("SELECT * FROM t_user WHERE role_id = (SELECT id FROM t_role WHERE label = #{roleLabel})")
    List<User> selectUserListByRoleLabel(String roleLabel);

    @Select("SELECT * FROM t_user WHERE dept_id = #{deptId}")
    List<User> selectUserListByDeptId(Integer deptId);

    @Select("SELECT image FROM t_user")
    List<String> selectImageList();
}